/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package au.edu.swin.swinvehicle.driverlicencetype;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Administrator
 */
@Stateless
public class DriverLicenceTypeManagerBean implements DriverLicenceTypeManagerRemote {

    @PersistenceContext
    private EntityManager em;

    public List<DriverLicenceTypeTO> getAllDriverLicenceTypes() throws DriverLicenceTypeManagerException {
        try {
            List<DriverLicenceTypeTO> results = new ArrayList<DriverLicenceTypeTO>();
            Query allDriverLicenceTypesQuery = this.em.createNamedQuery("findAllDriverLicenceTypes");
            List dbResults = allDriverLicenceTypesQuery.getResultList();
            for (int i = 0; i < dbResults.size(); i++) {
                DriverLicenceTypeEntity dlt = (DriverLicenceTypeEntity) dbResults.get(i);
                results.add(dlt.getData());
            }
            return results;
        } catch (Exception e) {
            throw new DriverLicenceTypeManagerException("Cannot get all driver licence types", e);
        }
    }
}
